use std::env;
use surrealdb::Surreal;
use surrealdb::engine::local::{Db, File};

pub async fn init_db() -> Surreal<Db> {
    // 设置本地路径
    let current_folder = env::current_exe().unwrap().parent().unwrap().to_path_buf();
    log::debug!("当前目录:{current_folder:?}");
    let db_path = current_folder.join("surrealdb.db");
    log::debug!("db路径:{db_path:?}");
    let db = Surreal::new::<File>(db_path).await.unwrap();
    let namespace_name = "ns1";
    let db_name = "db1";
    log::debug!("初始化DB namespace_name: {namespace_name}, db_name: {db_name}");
    db.use_ns(namespace_name).use_db(db_name).await.unwrap();
    db
}